import { FormField } from '@/components'

export const defaultTheme = {
  sysSubColorConfigUserId: 0,
  dto: {
    sub: {
      sysSubColorConfigId: 0,
      configName: '默认',
      configCode: '#2f5aa3'
    },
    button: [
      {
        sysSubColorConfigId: 21,
        configName: '新增',
        configCode: '#5C7CF7'
      },
      {
        sysSubColorConfigId: 22,
        configName: '复制类',
        configCode: '#5C7CF7'
      },
      {
        sysSubColorConfigId: 23,
        configName: '全选类',
        configCode: '#5C7CF7'
      },
      {
        sysSubColorConfigId: 24,
        configName: '预选类',
        configCode: '#5C7CF7'
      },
      {
        sysSubColorConfigId: 25,
        configName: '加载类',
        configCode: '#5C7CF7'
      },
      {
        sysSubColorConfigId: 26,
        configName: '查询类',
        configCode: '#5C7CF7'
      },
      {
        sysSubColorConfigId: 27,
        configName: '普通操作类',
        configCode: '#5C7CF7'
      },
      {
        sysSubColorConfigId: 28,
        configName: '下载类',
        configCode: '#5C7CF7'
      },
      {
        sysSubColorConfigId: 29,
        configName: '上传类',
        configCode: '#5C7CF7'
      },
      {
        sysSubColorConfigId: 30,
        configName: '刷新类',
        configCode: '#5C7CF7'
      },
      {
        sysSubColorConfigId: 31,
        configName: '导入类',
        configCode: '#5C7CF7'
      },
      {
        sysSubColorConfigId: 32,
        configName: '导出类',
        configCode: '#5C7CF7'
      },
      {
        sysSubColorConfigId: 33,
        configName: '任务执行类',
        configCode: '#30BEFF'
      },
      {
        sysSubColorConfigId: 34,
        configName: '更新类',
        configCode: '#30BEFF'
      },
      {
        sysSubColorConfigId: 35,
        configName: '反选类',
        configCode: '#30BEFF'
      },
      {
        sysSubColorConfigId: 36,
        configName: '同步类',
        configCode: '#30BEFF'
      },
      {
        sysSubColorConfigId: 37,
        configName: '发送类',
        configCode: '#30BEFF'
      },
      {
        sysSubColorConfigId: 38,
        configName: '审核类',
        configCode: '#30BEFF'
      },
      {
        sysSubColorConfigId: 39,
        configName: '反审核类',
        configCode: '#30BEFF'
      },
      {
        sysSubColorConfigId: 40,
        configName: '保存类',
        configCode: '#00CBAE'
      },
      {
        sysSubColorConfigId: 41,
        configName: '确定类',
        configCode: '#00CBAE'
      },
      {
        sysSubColorConfigId: 42,
        configName: '报送类',
        configCode: '#00CBAE'
      },
      {
        sysSubColorConfigId: 43,
        configName: '删除类',
        configCode: '#FB695A'
      },
      {
        sysSubColorConfigId: 44,
        configName: '作废类',
        configCode: '#FB695A'
      },
      {
        sysSubColorConfigId: 45,
        configName: '撤销撤单类',
        configCode: '#848FBC'
      },
      {
        sysSubColorConfigId: 46,
        configName: '重置类',
        configCode: '#848FBC'
      },
      {
        sysSubColorConfigId: 47,
        configName: '撤单类',
        configCode: '#848FBC'
      },
      {
        sysSubColorConfigId: 48,
        configName: '撤销类',
        configCode: '#848FBC'
      },
      {
        sysSubColorConfigId: 53,
        configName: '取消类',
        configCode: '#848FBC'
      },
      {
        sysSubColorConfigId: 49,
        configName: '编辑类',
        configCode: '#A678FC'
      },
      {
        sysSubColorConfigId: 50,
        configName: '设置类',
        configCode: '#A678FC'
      },
      {
        sysSubColorConfigId: 51,
        configName: '帮助类',
        configCode: '#A678FC'
      },
      {
        sysSubColorConfigId: 52,
        configName: '暂停类',
        configCode: '#FAA145'
      },
      {
        sysSubColorConfigId: 54,
        configName: '其他类',
        configCode: '#FAA145'
      }
    ],
    title: '默认'
  }
}

export const dialogFields: FormField[] = [
  {
    key: 'title',
    label: '主题名称',
    tag: 'ElInput',
    validateRules: [
      {
        required: true,
        message: '请输入',
        trigger: 'change'
      }
    ]
  }
]

export const colorToRgba = (color, alpha = 0.3) => {
  color = rgbToHex(color)
  // 十六进制颜色值的正则表达式
  const reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/
  /* 16进制颜色转为RGB格式 */
  let sColor = color.toLowerCase()
  if (sColor && reg.test(sColor)) {
    if (sColor.length === 4) {
      let sColorNew = '#'
      for (let i = 1; i < 4; i += 1) {
        sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1))
      }
      sColor = sColorNew
    }
    // 处理六位的颜色值
    const sColorChange = []
    for (let i = 1; i < 7; i += 2) {
      sColorChange.push(parseInt('0x' + sColor.slice(i, i + 2)))
    }
    // return sColorChange.join(',')
    return 'rgba(' + sColorChange.join(',') + ',' + alpha + ')'
  } else {
    return sColor
  }
}

export const rgbToHex = (rgb) => {
  const _this = rgb
  const reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/
  if (/^(rgb|RGB)/.test(_this)) {
    const aColor = _this.replace(/(?:\(|\)|rgb|RGB)*/g, '').split(',')
    let strHex = '#'
    for (let i = 0; i < aColor.length; i++) {
      let hex = Number(aColor[i]).toString(16)
      hex = String(hex).length == 1 ? 0 + '' + hex : hex // 保证每个rgb的值为2位
      if (hex === '0') {
        hex += hex
      }
      strHex += hex
    }
    if (strHex.length !== 7) {
      strHex = _this
    }
    return strHex
  } else if (reg.test(_this)) {
    const aNum = _this.replace(/#/, '').split('')
    if (aNum.length === 6) {
      return _this
    } else if (aNum.length === 3) {
      let numHex = '#'
      for (let i = 0; i < aNum.length; i += 1) {
        numHex += aNum[i] + aNum[i]
      }
      return numHex
    }
  } else {
    return _this
  }
}
